<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>仓库查看</title>
    <link rel="stylesheet" href="../../../../public/dist/css/layui.css" />
    <link rel="stylesheet" href="../../../../public/font/iconfont.css" />
    <link rel="stylesheet" href="../../../../css/twocss/commit.css" />
</head>

<body>
    <form class="layui-form" action="">
        <div class="select common">
            <div class="select-title">查询条件</div>

            <div class="select-con">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">仓库:</label>
                        <div class="layui-input-inline">
                            <select class="Namerawmaterials" lay-filter="TMADE">
                  <option value="">请选择</option>
                </select>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">二级仓库:</label>
                        <div class="layui-input-inline">
                            <select class="erji" lay-filter="shas">
                  <option value="">请选择</option>
                </select>
                        </div>
                    </div>
                </div>

                <div class="select-btn">
                    <div class="layui-bg-green comquery   Rawquery">查询</div>
                    <div class="layui-bg-green comquery   reset">重置</div>
                </div>
            </div>
        </div>
    </form>

    <div class="common-padding">
        <table class="layui-hide" id="test" lay-filter="testdome"></table>
    </div>
</body>

<!-- 里面的查看 -->
<script type="text/html" id="More">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
</script>

<!-- 查看的内容 -->
<script type="text/html" id="contentquery">
    <div class="select common">

        <div class="select-title" style="border-bottom:0px;background-color: #f3f3f3;">
            基本信息
        </div>

        <ul class="basis-h">
            {{each lists}}
            <li>
                <label>创建时间:</label>
                <p>{{$value.createon}}</p>
            </li>
            <li>
                <label>仓库:</label>
                <p>{{$value.parentname}}</p>
            </li>
            <li>
                <label>二级仓库:</label>
                <p>{{$value.storagename}}</p>
            </li>

        </ul>

        {{/each }}
    </div>
</script>

<script src="../../../../js/common/jquery.min.js"></script>
<script src="../../../../js/common/api.js"></script>
<script src="../../../../public/dist/layui.js" charset="utf-8"></script>
<script src="../../../../js/common/template-web.js"></script>
<script>
    layui.use(["table", "form"], function() {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        nas();

        function nas() {
            //一级仓库
            Theoldcuiway("plant/getyjck", {
                    repositorytype: 12
                }, "GET").done(function(resp) {
                    console.log(resp)
                    $(".Namerawmaterials").children().remove();
                    $(".Namerawmaterials").append(new Option("---请选择---", ""));
                    $.each(resp.data, function(index, item) {
                        $(".Namerawmaterials").append(
                            new Option(item.storagename, item.id)
                        ); // 下拉菜单里添加元素
                    });
                    layui.form.render("select");
                    return;
                })
                .fail(function(err) {
                    console.log(err);
                });

            //一级仓库选择出二级仓库
            form.on("select(TMADE)", function(data) {
                console.log(data.value)
                if (data.value != "") {
                    Theoldcuiway("plant/getejck", {
                            storageId: data.value
                        }, "GET").done(function(resp) {
                            console.log(resp)
                            $(".erji").children().remove();
                            $(".erji").append(new Option("---请选择---", ""));
                            $.each(resp.data, function(index, item) {
                                $(".erji").append(new Option(item.storagename, item.parentid)); // 下拉菜单里添加元素
                            });
                            layui.form.render("select");
                            return;
                        })
                        .fail(function(err) {
                            console.log(err);
                        });
                } else {
                    $(".erji").children().remove();
                    $(".erji").append(new Option("---请选择---", ""));
                    layui.form.render("select");
                }

                return;
            });
        }

        //监听表格里面按钮
        table.on("tool(testdome)", function(obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event;
            if (layEvent === "detail") {
                Toview(data.id);
            }
        });

        function Toview(dat) {
            layer.open({
                type: 1,
                title: "查看",
                shadeClose: true, //是否点击遮罩关闭
                anim: 5, //弹出动画
                scrollbar: false, //窗口外滚动条是否出现
                skin: "layui-layer-rim", //加上边框
                area: ["800px", "300px"], //宽高
                content: '<div class="ssss"></div>',
                success: function(layero, index) {
                    Theoldcuiway(
                            "plant/getCkxx", {
                                ckxxId: dat
                            },
                            "GET"
                        )
                        .done(function(resp) {
                            var lists = resp.data;
                            if (lists.createon == null || lists.createon == "") {
                                lists.createon = "";
                            } else {
                                lists.createon = times(lists.createon);
                            }
                            var d = [];
                            var t = {};
                            d.push(lists);
                            console.log(lists);
                            t.lists = d;
                            console.log(t);
                            var html = template("contentquery", t);
                            $(".ssss").html(html);
                        })
                        .fail(function(err) {
                            console.log(err);
                        });
                }
            });
        }

        function times(t) {
            return (t = t.split("T")[0]);
        }

        //获取列表
        var tableIns = table.render({
            elem: "#test",
            url: baseaip + "plant/ckgl/ckck",
            method: "GET",
            where: {
                repositorytype: "2"
            },
            headers: {
                Authorization: "Bearer" + " " + sessions
            },
            request: {
                pageName: "page",
                limitName: "limit"
            },
            limits: [10, 20],
            toolbar: "#toolbarinter",
            parseData: function(res) {
                //res 即为原始返回的数据
                console.log(res);
                return {
                    code: res.code, //解析接口状态
                    msg: res.msg, //解析提示文本
                    totalNum: res.data.totalElements, //解析数据长度
                    lists: res.data.content //解析数据列表
                };
            },
            response: {
                statusName: "code", //数据状态的字段名称，默认：code
                statusCode: 200, //成功的状态码，默认：0
                msgName: "msg", //状态信息的字段名称，默认：msg
                countName: "totalNum", //数据总数的字段名称，默认：count
                dataName: "lists" //数据列表的字段名称，默认：data
            },
            cellMinWidth: 80,
            page: {
                //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ["prev", "page", "next", "skip", "count"], //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                groups: 5, //只显示 1 个连续页码
                first: true, //不显示首页
                last: true, //不显示尾页
                prev: "上一页",
                next: "下一页",
                theme: "#c81623"
            },
            // height: 'full-20',//满高
            cols: [
                [{
                    title: "编号",
                    type: "numbers",
                    align: "center",
                    fixed: "left"
                }, {
                    field: "parentname",
                    title: "仓库",
                    minWidth: 120,
                    align: "center"
                }, {
                    field: "storagename",
                    title: "二级仓库",
                    align: "center",
                    minWidth: 150
                }, {
                    field: "wealth",
                    width: 137,
                    title: "更多",
                    minWidth: 20,
                    align: "center",
                    fixed: "right",
                    toolbar: "#More"
                }]
            ]
        });

        /*查询*/
        $(".Rawquery").click(function() {
            if ($(".Namerawmaterials").val() == "" && $(".erji").val() == "") {
                layer.msg("请输入查询条件！", {
                    time: 1000,
                    offset: "t"
                });
                return;
            }

            var datelist = {
                storageId: $(".Namerawmaterials").val(),
                areaId: $(".erji").val(),
                repositorytype: "2"
            };

            tableIns.reload({
                where: datelist,
                request: {
                    pageName: "currentPage", //页码的参数名称，默认：page
                    limitName: "pageSize" //每页数据量的参数名，默认：limit
                },
                page: {
                    curr: 1, //重新从第 1 页开始
                    layout: ["prev", "page", "next", "skip", "count"]
                }
            });
        });

        /*重置*/
        $(".reset").click(function() {
            nas();
            $(".erji")
                .children()
                .remove();
            $(".erji").append(new Option("---请选择---", ""));
            tableIns.reload({
                where: {
                    repositorytype: "2"
                },
                page: {
                    curr: 1, //重新从第 1 页开始
                    layout: ["prev", "page", "next", "skip", "count"]
                }
            });
        });
    });
</script>

</html>